// pages/my/goldcoin/goldcoin.js

const App = getApp()

Page({
  data: {
    goldcoin: {
      items: [
        {
          name:'淘淘领',
          time:'2017-10-31 22:45:10',
          goldcoin:'+200'
        },
        {
          name: '签到赠送',
          time:'2017-10-31 22:45:10',
          goldcoin: '-30'
        }
      ],
      params: {
        page: 1,
        limit: 10,
      },
      paginate: {total:2}      
    },

    prompt: {
      hidden: !0,
      icon: '../../../image/empty.png',
      title: '您还没有金币！',
      text: '赶快去淘金币',
    },
  },

  onLoad() {
    //this.goldcoin = App.HttpResource('/goldcoin/:id', {id: '@id'})
    //this.onPullDownRefresh()
  },

  initData() {
    this.setData({
      goldcoin: {
        items: [],
        params: {
          page: 1,
          limit: 10,
        },
        paginate: {}
      }
    })
  },



  getList() {
    const goldcoin = this.data.goldcoin
    const params = goldcoin.params

    // // App.HttpService.getGoldcoinList(params)
    this.goldcoin.queryAsync(params)
      .then(res => {
        const data = res.data
        console.log(data)
        if (data.meta.code == 0) {
          goldcoin.items = [...goldcoin.items, ...data.data.items]
          goldcoin.paginate = data.data.paginate
          goldcoin.params.page = data.data.paginate.next
          goldcoin.params.limit = data.data.paginate.perPage
          this.setData({
            goldcoin: goldcoin,
            'prompt.hidden': goldcoin.items.length,
          })
        }
      })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    console.info('onPullDownRefresh')
    this.initData()
    this.getList()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.info('onReachBottom')
    if (!this.data.goldcoin.paginate.hasNext) return
    this.getList()
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }








})


